package net.zoneland.knowledge.enums;

import org.apache.commons.lang3.StringUtils;

/**
 * 会议签到excel导入字段枚举
 */
public enum MeetingSignInEnum {
    // 参会人员导入字段
    MEETING_ORDER("序号\r\n（必填）", "order", "序号不能为空;"),
    MEETING_DEPT_NAME("部门\r\n（必填）", "deptName", "部门不能为空;"),
    MEETING_JOB("职务\r\n（必填）", "job", "职务不能为空;"),
    MEETING_SIGN_IN_USER_NAME("姓名\r\n（必填）", "signInUserName", "姓名不能为空;"),
    MEETING_EMP_NO("员工编号\r\n（可选）", "empNo"),
    MEETING_MOBILE("手机号码\r\n（必填）", "mobile", "手机号码不能为空;"),
    MEETING_SIGN_IN_USER_ID("签到人员ID", "signInUserId"),
    ;
    private String title;
    private String field;

    /**
     * 验证说明信息.
     */
    private String validInfo;

    MeetingSignInEnum(String title, String field, String validInfo) {
        this.title = title;
        this.field = field;
        this.validInfo = validInfo;
    }

    MeetingSignInEnum(String title, String field) {
        this.title = title;
        this.field = field;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getField() {
        return field;
    }

    public String getValidInfo() {
        return validInfo;
    }

    public void setValidInfo(String validInfo) {
        this.validInfo = validInfo;
    }

    public void setField(String field) {
        this.field = field;
    }

    public static String getFieldByTitle(String title) {
        for (MeetingSignInEnum commonEnum : MeetingSignInEnum.values()) {
            if (editTitle(title).equals(editTitle(commonEnum.getTitle()))) {
                return commonEnum.getField();
            }
        }
        return "";
    }

    /**
     * 编辑标题,去除特殊字符(空格、回车、换行),便于兼容匹配.
     * @param title 标题
     * @return 修改后的标题
     */
    public static String editTitle(final String title) {
        return StringUtils.isNotBlank(title) ? title.replaceAll("[\\n\\r\\s]", "") : title;
    }
}
